unit ufraBookmarks;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, ufraRegListViewTreeViewCombo, IniFiles,
  JvComponentBase, JvSearchFiles, ActnList, Menus;

type
  TfraBookmarks = class(TFrame)
    fraView: TfraListviewTreeviewCombo;
    jvSearchFiles: TJvSearchFiles;
    mnuTreeView: TPopupMenu;
    ActionList: TActionList;
    actReloadBookmarks: TAction;
    Reload1: TMenuItem;
    procedure jvSearchFilesError(Sender: TObject; var Handled: Boolean);
    procedure jvSearchFilesProgress(Sender: TObject);
    procedure actReloadBookmarksExecute(Sender: TObject);
  private
    { Private declarations }
    IniFile   :     TIniFile;

  public
    { Public declarations }
    PROCEDURE LoadBookmarks();
    CONSTRUCTOR Create(AOwner : TComponent); override;
    DESTRUCTOR Destroy(); override;
  end;

implementation
CONST
  BOOKMARK_DIR        =       'Bookmarks\';

{$R *.dfm}



procedure TfraBookmarks.actReloadBookmarksExecute(Sender: TObject);
begin
LoadBookmarks;
end;

CONSTRUCTOR TfraBookmarks.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  LoadBookmarks;
end;

DESTRUCTOR TfraBookmarks.Destroy;
begin
//  if Assigned(INiFile) then IniFile.Free;

  Inherited Destroy();
End;

procedure TfraBookmarks.jvSearchFilesError(Sender: TObject;
  var Handled: Boolean);
begin
ShowMessage('Unknown Error while searching: ' + jvSearchFiles.RootDirectory);
Handled := True;
end;

procedure TfraBookmarks.jvSearchFilesProgress(Sender: TObject);
begin
//pbSearching.Max := (jvSearchFiles.Files.Count + jvSearchFiles.Directories.Count);
//pbSearching.Position := pbSearching.Position + 1;
end;

PROCEDURE TfraBookmarks.LoadBookmarks();
Var
  AppPath   :   String;
  i         :   integer;
  Sections  :   TSTringList;
  NodeItem  :   TTreeNode;
  RootItem  :   TTreeNode;
Begin
Sections := TSTringList.Create;

AppPath := ExtractFilePath(ParamStr(0));
if AppPath[Length(AppPath)] <> '\' then AppPath := AppPath + '\';

if NOT DirectoryExists(AppPath + BOOKMARK_DIR) then
   Begin
   Try
      Begin
      MkDir(AppPath + BOOKMARK_DIR);
      End;
   Except
      Begin
      ShowMessage('Unable to create folder ' + AppPath + BOOKMARK_DIR);
      End;
   End;
   End;

fraView.TreeView.Items.Clear;
fraView.ListView.Items.Clear;
jvSearchFiles.RootDirectory := AppPath + BOOKMARK_dir;
jvSearchFiles.Search;
while jvSearchFiles.Searching do
   Begin
   // wait while searching...
   End;

fraView.TreeView.Items.BeginUpdate;
RootItem := fraView.TreeView.Items.Add(nil,'Bookmarks');
for i := 0 to jvSearchFiles.Files.Count - 1 do
    Begin
    Try
      Begin
      IniFile := TIniFile.Create(jvSearchFIles.Files.Strings[i]);
      NodeItem := fraView.TreeView.Items.AddChild(RootItem,ExtractFileName(jvSearchFiles.Files.Strings[i]));
      End;
    except
      Begin

      End;
    End;
    IniFile.Free;
    End;
fraView.TreeView.Items.EndUpdate;

Sections.Free;
end;


end.
